package org.example.travel.schedule;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.travel.service.ScenicSpotService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
@Slf4j
public class ScenicScheduler {

    private final ScenicSpotService scenicSpotService;

    // 每 5 分钟同步日志到数据库
    @Scheduled(cron = "0 */5 * * * ?")
    public void flushLogsToDatabase() {
        log.info("[景点] 开始同步 Redis 日志到数据库...");
        scenicSpotService.flushScenicLogs();
    }

    // 每天凌晨 2 点更新热度和热门缓存
    @Scheduled(cron = "0 0 2 * * ?")
    public void updateHeatAndCache() {
        log.info("[景点] 开始更新热度值和缓存...");
        scenicSpotService.updateHeatScoresAndCache();
    }

    // 每 7 天清理一次行为日志表
    @Scheduled(cron = "0 0 3 */7 * ?")
    public void clearOldLogs() {
        log.info("[景点] 清理 7 天前的日志...");
        // 实际清理逻辑建议写到 scenicSpotService 中
    }
}